
/**
 * Namespace    Classes.Entities
 * Class        Customer
 * Author       Bram Vandenbussche
 * Description  Provides object logic for a customer
 * Version      1.0
**/

Customer = function() {
	
	this.ID = 0;
	
	this.Firstname = '';
	this.Lastname = '';
	
	this.Email = '';	
	this.Gender = 0;
	this.Birthday = '';
	this.DateAdded = '';
	this.DateUpdated = '';
	
}

Customer.prototype.Serialize = function() {
	var str = '';

    str += '<customer>';
    
    str += '<id>' + this.ID + '</id>';
    
    str += '<firstname>' + this.Firstname + '</firstname>';    
    str += '<lastname>' + this.Lastname + '</lastname>';
    str += '<email>' + this.Email + '</email>';
    str += '<gender>' + this.Gender + '</gender>';
	str += '<dob>' + this.Birthday + '</dob>';
	str += '<date_add>' + this.DateAdded + '</date_add>';
	str += '<date_upd>' + this.DateUpdated + '</date_upd>';
	
	str += '</customer>';
	
	return str;
}


Customer.prototype.Deserialize = function(xml) {
	this.ID = $("id", xml).html();
    
    this.Firstname = $("firstname", xml).html();
    this.Lastname = $("lastname", xml).html();
    this.Email = $("email", xml).html();
    this.Gender = $("gender", xml).html();
	this.Birthday = $("dob", xml).html();
    
	this.DateAdded = $("date_add", xml).html();
	this.DateUpdated = $("date_upd", xml).html();
}


Customer.prototype.AssembleFromJson = function(json) {
	this.ID = json.id;
    
	this.Firstname = json.firstname;
	this.Lastname = json.lastname;    
    this.Email = json.email;	
	this.Gender = json.id_gender;
	this.Birthday = json.birthday;
    
	this.DateAdded = json.date_add;
	this.DateUpdated = json.date_upd;
}


Customer.prototype.Name = function() {
	return this.Firstname + ' ' + this.Lastname;
}


Customer.prototype.Address = function() {
     return AddressService.GetAddressByCustomerID(this.ID);
}